; (function ($) {
	var turl=""
	$.fn.ajaxSubFrom=function(frm){
		//console.log("ajaxsubformP2p",frm);
		//turl = frm.action;
		var options  = {
			async:false,
			cache: false,
			resetForm: false,
			//dataType:  frm.dataType,
			dataType:  'json',
			type:  frm.method,
			url: frm.action,
			beforeSubmit:  showRequest,  // pre-submit callback
			success:       showResponse,  // post-submit callback
			error:showError

		};
		$(this).ajaxSubmit(options );
		return false; // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
	}

	$.fn.ajaxSubFromDialog=function(frm){
		var options  = {
			async:false,
			cache: false,
			resetForm: false,
			//dataType:  frm.dataType,
			dataType:  'json',
			type:  frm.method,
			url: frm.action,
			beforeSubmit:  showRequest,  // pre-submit callback
			success:       showResponseDialog,  // post-submit callback
			error:showError

		};
		$(this).ajaxSubmit(options );
		return false; // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
	}

	// pre-submit callback
	function showRequest(formData, jqForm, options) {
		//return $(this).form('validate');
		/*swal({   title: "你确定要提交吗?",
		 text: "你将提交不能修改！!",
		 type: "warning",
		 showCancelButton: true,
		 confirmButtonColor: "#DD6B55",
		 confirmButtonText: "确定",
		 closeOnConfirm: false },
		 function(){
		 swal("审核!", "成功！！", "success");
		 });*/
	}

	// post-submit callback
	function showResponse(responseText, statusText)  {
		if(responseText.status!=0){
			if(responseText.status==200){
				swal({
					title:  "成功!",
					text: responseText.msg,
					type: "success",
					timer: 3000,
					showCancelButton: true,
					closeOnConfirm: false,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}
			if(responseText.status==404){
				swal({
					title:  "错误!",
					text: responseText.msg,
					type: "error",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}


			if( responseText.status==400){
				swal({
					title:  "警告!",
					text: responseText.msg,
					type: "warning",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}

			if(responseText.status==500 ){
				swal({
					title:  "警告!",
					text: responseText.msg,
					type: "warning",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}
		}else {
			swal("提示", responseText.msg, "warning")
		}
		//if(responseText.url!=undefined || responseText.url!=""|| responseText.url!=" " || responseText.url!=null|| responseText.url!="null" || responseText.url.length!=0 ||typeof (responseText.url) != "undefined" ){
		if( responseText.url!=null){
			window.location.href  =   responseText.url;
		}else{
			//javascript:history.back();
		}

		return false;
	}

	// post-submit dialog callback
	function showResponseDialog(responseText, statusText)  {

		if(responseText.status!=0){
			if(responseText.status==200){
				swal({
					title:  "成功!",
					text: responseText.msg,
					type: "success",
					timer: 3000,
					showCancelButton: true,
					closeOnConfirm: false,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}
			if(responseText.status==404){
				swal({
					title:  "错误!",
					text: responseText.msg,
					type: "error",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}


			if( responseText.status==400){
				swal({
					title:  "警告!",
					text: responseText.msg,
					type: "warning",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}

			if(responseText.status==500 ){
				swal({
					title:  "警告!",
					text: responseText.msg,
					type: "warning",
					showCancelButton: true,
					closeOnConfirm: false,
					timer: 3000,
					confirmButtonText: "确定",
					cancelButtonText:"取消"
				});
			}
		}else {
			swal("提示", responseText.msg, "warning")
		}
		//if(responseText.url!=undefined || responseText.url!=""|| responseText.url!=" " || responseText.url!=null|| responseText.url!="null" || responseText.url.length!=0 ||typeof (responseText.url) != "undefined" ){
		/*if( responseText.url!=null){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
			window.location.href  =   responseText.url;
		}else{
			//javascript:history.back();
		}*/
		return false;
	}
	function showError(responseText, statusText)  {
		//$("#dialog").hDialog('close',{box:'#dialog'});
		swal({
			title:  "错误!",
			text: responseText.msg,
			type: "error",
			timer: 2000,
			confirmButtonText: "确定",
			cancelButtonText:"取消"
		});
	}




})(jQuery);

